package org.wsff.tools.api.gateway.error;

/**
 * 网关错误工厂
 * 
 * @author ryan
 * @version Id: GatewayErrorFactory.java, v 0.1 2022-01-18 15:44 ryan Exp $$
 */
public class GatewayErrorFactory extends AbstractErrorMessageFactory {

    /**
     * 获取ErrorFactory单例
     *
     * @return instance instance
     */
    public static GatewayErrorFactory getInstance() {
        return GatewayErrorFactoryHolder.INSTANCE;
    }

    /**
     * Provide ERROR bundle name string.
     *
     * @return the string
     */
    @Override
    protected String provideErrorBundleName() {
        return "gateway";
    }

    /**
     * 系统异常, 详情:{0}
     *
     * @param error 错误消息
     * @return 异常
     */
    public GatewayError sysError(String error) {
        return createError("E0001", error);
    }

    /**
     * 参数{0}不能为空
     * @param param 参数
     * @return 异常
     */
    public GatewayError paramNull(String param) {
        return createError("E0002", param);
    }

    /**
     * 参数{0}非法
     *
     * @param param 参数名
     * @return 异常
     */
    public GatewayError invalidParamError(String param) {
        return createError("E0003", param);
    }

    /**
     * 参数{0},内容:{1} 不合法, 正确的格式:{2}
     *
     * @param type 类型
     * @param message 错误消息
     * @param legal 正确的格式
     * @return 异常
     */
    public GatewayError illegalParam(String type, String message, String legal) {
        return createError("E0004", type, message, legal);
    }

    /**
     * 参数{0}格式错误，正确的格式:{1}
     *
     * @return 异常
     */
    public GatewayError paramFormatError(Object obj, String format) {
        return createError("E0005", obj, format);
    }

    /**
     * GatewayErrorFactory Holder
     */
    private static final class GatewayErrorFactoryHolder {
        /** instance */
        private static final GatewayErrorFactory INSTANCE = new GatewayErrorFactory();
    }
}